﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using U.B.ErrorCode;
using U.B.WriteApi.Command;

namespace U.B.WriteApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMediator _mediator;
        public MenuController(IMediator mediator)
        {
                _mediator = mediator;
        }
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<string>> AddMenu(AddMenuCommand command)
        {
                return _mediator.Send(command);
        }
        /// <summary>
        /// 菜单删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>> DeleteMenu([FromQuery] DelMenuCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 菜单修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<object>> UpdateMenu(UpdateMenuCommand command)
        {
                return _mediator.Send(command);
        }
        /// <summary>
        /// 角色菜单添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>>AddRoleMenu(AddRoleMenuCommand command)
        {
                return await _mediator.Send(command);
        }
        /// <summary>
        /// 角色菜单删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>>DeleteRoleMenu(DelRoleMenuCommand command)
        {
                return await _mediator.Send(command);
        }
    }
}
